#include<stdio.h>
unsigned setbits(unsigned,int,int,unsigned);
int main()
{
  unsigned x,y;
  int n,p;
  printf("\nenter two numbers");
  scanf("%u %u",&x,&y);
  getchar();
  printf("enter the bit position to be read from");
  scanf("%d",&p);
  printf("enter the number of bits to be read");
  scanf("%d",&n);
  printf("%u",setbits(x,p,n,y));
  return 0;
}

unsigned setbits(unsigned x,int p,int n,unsigned y)
{
  return ((((~(~0 << n)) & y)<<p+1-n) + ((~((~(~0 <<n))<<p+1-n)) & x));
}

    
